package com.csdj.controller.sy;

/**
 * @author 涵哥
 * @date 2023-08-28 14:10
 */

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.csdj.common.utils.ResponseResult;
import com.csdj.pojo.SyCosttype;
import com.csdj.pojo.SyCosttype;
import com.csdj.service.SyCosttypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 费用类型管理
 */
@RestController
@RequestMapping("/sy/costType")
public class SystemCostTypeController {
    @Autowired
    private SyCosttypeService syCostTypeService;

    /**
     * 获取费用类型列表
     * @return
     */
    @GetMapping
    public ResponseResult list(Integer kind){
        List<SyCosttype> list = syCostTypeService.list(Wrappers.<SyCosttype>lambdaQuery()
                        .eq(SyCosttype::getKind,kind)
                .eq(SyCosttype::getDiskabled
                ,0).orderByDesc(SyCosttype::getId));
        return ResponseResult.okResult(list);
    }

    /**
     * 新增费用类型
     * @param syCosttype
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody SyCosttype syCosttype){
        // 默认为使用
        syCosttype.setDiskabled(0);
        return ResponseResult.okResult(syCostTypeService.save(syCosttype));
    }

    /**
     * 删除费用类型
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public ResponseResult remove(@PathVariable Integer id){
        return ResponseResult.okResult(syCostTypeService.removeById(id));
    }

    /**
     * 根据id查找费用类型
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public ResponseResult getOne(@PathVariable Integer id){
        return ResponseResult.okResult(syCostTypeService.getById(id));
    }

    /**
     * 修改费用类型
     * @param SyCosttype
     * @return
     */
    @PutMapping
    public ResponseResult update(@RequestBody SyCosttype SyCosttype){
        return ResponseResult.okResult(syCostTypeService.updateById(SyCosttype));
    }
}
